package com.cyc.common.enums;

/**
 * @author fei
 */

public enum CodeEnum {
    //系统内部错误
    SYSTEM_INTERNAL_ERROR("0000", "System Internal Error"),
    //请求路径不合法
    REQUEST_PATH_NOT_ALLOWED("0001", "The request path not allowed"),
    //queryParams无效
    QUERY_PARAMETER_INVALID("0002", "The query parameter is invalid"),
    //缺少signTimestamp参数
    SIGN_TIMESTAMP_IS_MISSING("0003", "The request missing parameter: signTimestamp"),
    //缺少nonce参数
    NONCE_IS_MISSING("0004", "The request missing parameter: nonce"),
    //缺少appkey参数
    APP_KEY_IS_MISSING("0005", "The request missing parameter: appkey"),
    //缺少digitalSign参数
    DIGITAL_SIGN_IS_MISSING("0006", "The request missing parameter: digitalSign"),
    //请求app-server异常
    REQUEST_APP_SERVER_ERROR("0007", "Call app-server check sign error"),
    //缺少Authorization参数
    AUTHORIZATION_IS_MISSING("0008", "The request missing parameter: Authorization"),
    //请求user异常
    REQUEST_USER_ERROR("0009", "Call user check token error"),
    //authorization错误
    AUTHORIZATION_INVALID("0010", "Check authorization failed, authorization is invalid"),
    //签名错误
    DIGITAL_SIGN_INVALID("0011", "Check digitalSign failed, digitalSign is invalid"),
    //adminToken错误
    ADMIN_TOKEN_INVALID("0012", "Check adminToken failed, adminToken is invalid"),
    //缺少Authorization参数
    ADMIN_TOKEN_IS_MISSING("0013", "The request missing parameter: token"),
    //请求admin-service异常
    REQUEST_ADMIN_SERVICE_ERROR("0014", "Call admin-service check adminToken error"),
    // 签名时间戳已过期
    SIGN_TIMESTAMP_HAS_EXPIRED("0015", "Sign timestamp has expired"),
    //时间戳有效期内nonce重复
    NONCE_REPEAT_DURING_TIME_STAMP_VALIDITY_PERIOD("0016", "Nonce repeat during time stamp validity period"),
    //appKey对应的品牌信息没有匹配到adminToken验证服务
    NO_MATCH_ADMIN_TOKEN_CHECK_SERVICE("0017", "The brand information corresponding to appKey does not"
            + " match the adminToken authentication service"),
    //appKey对应的品牌信息没有匹配到adminToken验证服务
    API_HYSTRIX_ERROR("0018", "hystrix error"),
    //非法标识符
    INVALID_TOKEN("0019", "Invalid token"),
    //数据不存在
    NO_DATA("0020", "Data does not exist"),
    //服务繁忙，请稍后试
    API_GATEWAY_SERVICE_IS_BUSY("0098", "The service is busy, please try again later"),
    //API网关未知错误
    API_GATEWAY_UNKNOWN_ERROR("0099", "ApiGateway unknown error"),
    //调用第三方系统出错
    CALL_THIRD_SYSTEM_ERROR("9998", "call third system error"),
    //未知错误
    OTHER("9999", "unrecognized error");

    private String code;
    private String msg;

    CodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * @param msg 消息
     * @return String
     * @author chenyunchang
     * @description 根据msg获取code
     * @date 2021-04-07 15:47:28
     */
    public static String getCode(String msg) {
        for (CodeEnum c : CodeEnum.values()) {
            if (c.getMsg().equals(msg)) {
                return c.code;
            }
        }
        return null;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
